﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DynaPrecision.LinearSystem
{
	/// <summary>
	/// Generating an array without an underlying storage, values and actions are supported by function calls
	/// </summary>
	/// <typeparam name="T"></typeparam>
	public class FunctionMappedArray<T> : IMultiDimensionalArray<T>
	{
		/// <summary>
		/// The function that used to obain a value when perform indexing on the array
		/// </summary>
		public Func<int[], T> Getter { get; set; }
		/// <summary>
		/// The function that set a specific index to a certain value
		/// </summary>
		public Action<T, int[]> Setter { get; set; }
		/// <summary>
		/// Use the length to set the corret dimensions and lengths
		/// </summary>
		public Func<int,int> LengthGetter { get; set; }
		public Func<int> DimensionGetter { get; set; }
		#region IMultiDimensionalArray<T> Members

		public T this[params int[] index]
		{
			get
			{
				return Getter(index);
			}
			set
			{
				Setter(value, index);
			}
		}

		public int GetLength(int DimensinNumber)
		{
			return LengthGetter(DimensinNumber);
		}

		public int Dimension
		{
			get { return DimensionGetter(); }
		}

		#endregion
	}
}
